package com.qianyanglong.m3u88.download.app.table.model;

import com.qianyanglong.m3u88.download.app.table.HomeTable;
import com.qianyanglong.m3u88.download.app.table.vo.HomeTableVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.util.List;

public class HomeTableModel implements TableModel {

    private static final Logger logger = LoggerFactory.getLogger(HomeTableModel.class);

    private String[] columnNames = {"ID","名称","地址","进度","操作"};

    private Class[] columnClasses = {Integer.class,String.class,String.class,String.class,String.class};

    private List<HomeTableVO> data= null;

    public HomeTableModel(List<HomeTableVO> data){
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return columnClasses[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        HomeTableVO homeTableVO = data.get(rowIndex);
        switch (columnIndex){
            case 0:
                return homeTableVO.getId();
            case 1:
                return homeTableVO.getName();
            case 2:
                return homeTableVO.getAddress();
            case 3:
                return homeTableVO.getProgress();
            case 4:
                return "按钮";
            default:
                return "错误";
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }


}
